﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using ScrappyDB.BaseClasses;

namespace ScrappyDB.Utilities
{
    public static class ExtensionMethods
    {
        /// <summary>
        /// Test to see if a ScrappyDbCollection<T> is null or empty
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="collection"></param>
        /// <returns></returns>
        public static bool IsNullOrEmpty<T>(this SdbCollection<T> collection) where T : class, new()
        {
            if (collection != null && collection.Count > 0)
                return false;

            return true;
        }

        /// <summary>
        /// Adds the "missing" AddRange functionality to collections
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="collection"></param>
        /// <param name="values"></param>
        public static void AddRange<T>(this Collection<T> collection, IEnumerable<T> values)
        {
            foreach (var item in values)
            {
                collection.Add(item);
            }
        }

    }
}